package com.example.demo.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.demo.bean.SWarehouse;
import com.example.demo.common.utils.Response;
import com.example.demo.mapper.SWarehouseMapper;
import com.example.demo.service.SWarehouseService;
import com.github.pagehelper.PageInfo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(tags="仓库信息服务")
@RestController
@RequestMapping("/warehouse")
public class SWarehouseController {
	@Autowired
	SWarehouseService swService;
	
	@GetMapping("/all")
	@ApiOperation(value = "查找所有仓库信息",notes="分页显示所有仓库信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "pageNum",value = "页码",defaultValue = "1"),	@ApiImplicitParam(name="pageSize",value = "每页显示个数",defaultValue = "3")	
	})
	public Response findAll(@RequestParam(defaultValue = "1")int pageNum,@RequestParam(defaultValue = "100")int pageSize) {
		PageInfo<SWarehouse> page=swService.findAllByPage(pageNum, pageSize);
		return Response.success(page);
	}
	
	@GetMapping("/by/condition")
	@ApiOperation(value = "按照条件检索仓库",notes = "按照id,区域id，管理员id进行查找")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "id",value = "编号"),
		@ApiImplicitParam(name = "regionId",value = "区域id"),
		@ApiImplicitParam(name = "managerId",value = "管理员id"),
		@ApiImplicitParam(name="pageNum",value = "页码"),
		@ApiImplicitParam(name = "pageSize",value = "每页个数")
	})
	public Response findByCondition(
			Integer id,
			Integer regionId,
			Integer managerId,
			@RequestParam(defaultValue ="1")int pageNum,
			@RequestParam(defaultValue = "3")int pageSize) {
		PageInfo<SWarehouse> page=swService.findByCondition(id, regionId, managerId, pageNum, pageSize);
		return Response.success(page);
	}
	
	@PostMapping("saveorupdate")
	@ApiOperation(value = "保存或更新信息")
	public Response saveOrUpdate(SWarehouse sw) {
		swService.saveOrUpdate(sw);
		return Response.success(sw.getId()==null?"添加仓库信息成功":"保存仓库信息成功");
	}
	@DeleteMapping("/delete/by/id")
	@ApiOperation(value = "按照id删除仓库")
	public Response deleteById(Integer id) {
		swService.deleteById(id);
		return Response.success("删除id为"+id+"的仓库信息成功");
	}
	@DeleteMapping("/batchdelete")
	@ApiOperation(value = "批量删除")
	public Response batchDelete(int [] id) {
		swService.batchDeleteById(id);
		return Response.success("删除成功");
	}
}
